import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Bg')
export class Bg extends Component {

    //将这个作为组件开放的属性
    @property(Node)
    bg1:Node = null;
    @property(Node)
    bg2:Node = null;

    //背景滚动速度
    @property
    speed:number = 100;


    start() {

    }

    update(deltaTime: number) {
        let weiYi = deltaTime * this.speed;
        // let bg1Position = this.bg1.position;
        // let bg2Position = this.bg2.position;

        // this.bg1.setPosition(bg1Position.x,bg1Position.y-weiYi,bg1Position.z);

        // this.bg2.setPosition(bg2Position.x,bg2Position.y-weiYi,bg2Position.z);
        this.bgWeiYi(this.bg1,weiYi);
        this.bgWeiYi(this.bg2,weiYi);

        
    }

    bgWeiYi(bg:Node,weiYi:number){
        let position = bg.position;
        bg.setPosition(position.x,position.y-weiYi,position.z);

        if(position.y <= -852){
            bg.setPosition(position.x,position.y + 852*2)
        }
    }
}


